import pandas as pd
import numpy as np
import math

# read file
filepath = "E:\\0S-lab\\0slab项目\\10襄阳\\multicenter\\out\\DBSCAN_100_20\\"
clusternames = ["all2008out_cluster.csv", "all2015out_cluster.csv", "all2017out_cluster.csv"]

for k in clusternames:
    f = open(filepath + k)
    df = pd.read_csv(f)
    f.close()

    # compute matrix
    n = df.shape[0]
    mat = np.zeros((n, n))
    for i in range(0, n):
        for j in range(0, n):
            if i == j:
                mat[i][j] = 0
            else:
                [x1, y1] = df["x"][i], df["y"][i]
                area1 = df["area"][i]
                [x2, y2] = df["x"][j], df["y"][j]
                area2 = df["area"][j]
                temp = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
                mat[i][j] = area1 * area2 / temp
    outname = filepath + k.split(".csv")[0] + '_mat.txt'
    np.savetxt(outname , mat, delimiter=' ', fmt="%.10f")






